// pages/welcomePage/welcomePage.js
var httpClient = require('../../utils/httpClient.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 登录
    var page = this;
    wx.login({
      success: function (res) {
        if (res.code) {
          httpClient.postNoMask("/wxAuth/login", res.code, function (result) {
            wx.setStorageSync('token', result);
              wx.redirectTo({ url: "/pages/chooseMode/chooseMode" });
            /*page.checkIfNew();*/
          });
        } else {
          wx.showModal({
            title: '提示',
            content: '请同意登录系统',
            showCancel: true
          });
        }
      }
    });
  },
  checkIfNew: function () {
    httpClient.getNoMask("/user/checkIfNew", function (result) {
      if (result) {
        wx.redirectTo({ url: "/pages/inputInfo/inputInfo" });
      } else {
        wx.redirectTo({ url: "/pages/chooseMode/chooseMode" });
      }
    });
  }
})